package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysAResidentList;
import com.ruoyi.system.service.ISysAResidentListService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 住户管理Controller
 * 
 * @author ruoyi
 * @date 2021-11-09
 */
@Controller
@RequestMapping("/system/resident")
public class SysAResidentListController extends BaseController
{
    private String prefix = "system/resident";

    @Autowired
    private ISysAResidentListService sysAResidentListService;

    @RequiresPermissions("system:resident:view")
    @GetMapping()
    public String resident()
    {
        return prefix + "/resident";
    }

    /**
     * 查询住户管理列表
     */
    @RequiresPermissions("system:resident:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysAResidentList sysAResidentList)
    {
        startPage();
        List<SysAResidentList> list = sysAResidentListService.selectSysAResidentListList(sysAResidentList);
        return getDataTable(list);
    }

    /**
     * 导出住户管理列表
     */
    @RequiresPermissions("system:resident:export")
    @Log(title = "住户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysAResidentList sysAResidentList)
    {
        List<SysAResidentList> list = sysAResidentListService.selectSysAResidentListList(sysAResidentList);
        ExcelUtil<SysAResidentList> util = new ExcelUtil<SysAResidentList>(SysAResidentList.class);
        return util.exportExcel(list, "住户管理数据");
    }

    /**
     * 新增住户管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存住户管理
     */
    @RequiresPermissions("system:resident:add")
    @Log(title = "住户管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysAResidentList sysAResidentList)
    {
        return toAjax(sysAResidentListService.insertSysAResidentList(sysAResidentList));
    }

    /**
     * 修改住户管理
     */
    @GetMapping("/edit/{residentId}")
    public String edit(@PathVariable("residentId") String residentId, ModelMap mmap)
    {
        SysAResidentList sysAResidentList = sysAResidentListService.selectSysAResidentListByResidentId(residentId);
        mmap.put("sysAResidentList", sysAResidentList);
        return prefix + "/edit";
    }

    /**
     * 修改保存住户管理
     */
    @RequiresPermissions("system:resident:edit")
    @Log(title = "住户管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysAResidentList sysAResidentList)
    {
        return toAjax(sysAResidentListService.updateSysAResidentList(sysAResidentList));
    }

    /**
     * 删除住户管理
     */
    @RequiresPermissions("system:resident:remove")
    @Log(title = "住户管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysAResidentListService.deleteSysAResidentListByResidentIds(ids));
    }
}
